home *** CD-ROM | disk | FTP | other *** search
- #include "chbuffer.hxx"
- #undef TEST
- /*
- -*++ char_buffer::put(): stick a character at the end of the buffer
- **
- ** (*++ history:
- ** 7 Dec 87 Bruce Eckel Creation date
- ** ++*)
- **
- ** (*++ detailed:
- ** ++*)
- */
-
- void char_buffer::put(char c) {
- if (index +1 == length) { error("buffer overflow"); return;}
- head[index++] = c;
- head[index] = 0; /* null-terminate */
- }
-
-
- /*
- -*++ char_buffer::get(): get a character from the end of the buffer
- **
- ** (*++ history:
- ** 7 Dec 87 Bruce Eckel Creation date
- ** ++*)
- **
- ** (*++ detailed:
- ** ++*)
- */
-
- char char_buffer::get() {
- if (--index < 0) { index = 0; return 0; }
- char c = head[index];
- head[index] = 0;
- return c;
- }
-
-
- #ifdef TEST
- main()
- {
- char c;
- char_buffer buf(80);
- while(cin.get(c), c != '\n')
- buf.put(c);
- cout << "dumping buf\n";
- buf.dump();
- }
- #endif